#!/bin/bash

set -x

if [ -n "${BASH_SOURCE[0]}" ]; then
	    SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    else
	        SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
fi
root=$SCRIPT_DIR/tmp
topdir=$root/root/rpmbuild
rm -fr $root
mkdir -p $topdir
mkdir -p ${topdir}/{SOURCES,SPECS}

tar cf ${topdir}/SOURCES/src.tar.gz src

rpmbuild --define "_topdir $topdir" -ba $SCRIPT_DIR/sysmonitor.spec
if [ $? = 0 ]; then
	cp ${topdir}/RPMS/aarch64/*.rpm $SCRIPT_DIR/
	rm -rf ${root}
fi


